package com.jzoom.zoom.admin.controllers;

import com.jzoom.zoom.admin.models.AdminDaoModel;
import com.jzoom.zoom.admin.models.DaoListener;
import com.jzoom.zoom.admin.models.DecorationTableService;
import com.jzoom.zoom.common.annotations.Inject;
import com.jzoom.zoom.common.utils.Classes;
import com.jzoom.zoom.dao.Dao;
import com.jzoom.zoom.web.utils.WebUtils;

/**
 * 如果要定制功能，建议使用本controller
 * @param <T>
 */
public class AbstractDaoController<T extends AdminDaoModel>  implements AdminController {
    @Inject(value = "admin")
    protected Dao baseDao;

    protected T model;

    @Inject
    private DaoListener daoListener;

    @Inject
    private DecorationTableService decorationTableService;


    @SuppressWarnings("unchecked")
    @Inject
    public void init() {
        Class<?> type = (Class<?>) Classes.getAllParameterizedTypes(getClass())[0];
        try {
            model = (T) WebUtils.getIoc().get(type);
            model.setDao(baseDao);
            model.setDecorationTableService(decorationTableService);
            model.setDaoListener(daoListener);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
